package com.sgb.kjwl.view.ui.adapter.enterprise;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemAddneedlistServiceBinding;
import com.sgb.kjwl.generated.callback.OnClickListener;
import com.sgb.kjwl.model.entity.enterprise.NeedListItemEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class AddNeedListServiceAdpater extends BaseRecycleAdapter<NeedListItemEntity> {
    TextView tv_typename;
    private ListonclickLister mlister;
    public AddNeedListServiceAdpater(Context context,  List<NeedListItemEntity> datas) {
        super(context, R.layout.item_addneedlist_service, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, NeedListItemEntity mItemmodel) {
        ItemAddneedlistServiceBinding bingding = (ItemAddneedlistServiceBinding)holder.getmBinding();
        bingding.setMItemmodel(mItemmodel);
        tv_typename = holder.getItem().findViewById(R.id.tv_typename);

        tv_typename.setText(TextUtils.isEmpty(mItemmodel.getCategoryFirstName())?
                "/":TextUtils.isEmpty(mItemmodel.getCategorySecondName())?
                mItemmodel.getCategoryFirstName():TextUtils.isEmpty(mItemmodel.getCategoryThirdName())?
                mItemmodel.getCategoryFirstName()+"-"+mItemmodel.getCategorySecondName():
                mItemmodel.getCategoryFirstName()+"-"+mItemmodel.getCategorySecondName()+"-"+mItemmodel.getCategoryThirdName());
        final int position = holder.getPosition();
        holder.getItem().findViewById(R.id.tv_btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mlister!=null){
                    mlister.click(v,position);
                }
            }
        });

        holder.getItem().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mlister!=null){
                    mlister.click(v,position);
                }
            }
        });
    }



    public void setOnclickLister(ListonclickLister lister){
        mlister = lister;
    }


    public interface ListonclickLister{
        public void click(View v,int position);
    }
}
